home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Development / REALbasic 5.5.5.dmg / REALbasic 5.5.5 Mac OS X / Read Me / Console RB Read Me.txt < prev    next >
Encoding:
Text File  |  2005-03-18  |  5.1 KB  |  84 lines

  1. Console RB Read Me
  2. by Aaron Ballman
  3.  
  4.     New, in REALbasic 5.5, is the ability to create console applications using REALbasic.
  5.  
  6. * What is a console application?
  7.  
  8.     A console application is one that contains no UI and works solely on the command line.  In OS X, that means your application runs within the terminal, on Windows, it will run from the command prompt and on Linux, it will run from the command line or a terminal window.
  9.  
  10.     Due to the lack of UI, the way a console application communicates with the user is through the Print and Input commands (or the StandardInputStream and StandardOutputStream classes).  I will describe the new classes, global methods and API changes below.
  11.  
  12. * What program design principles are different with a console application?
  13.  
  14.     When you make a GUI application, the program execution begins in the Application.Open event, and halts once you call Quit, or the user terminates your application thru the Quit menu.  Your program will stay loaded in memory and running until some user interaction tells it to stop (or you call Quit in your code).
  15.  
  16.     A console application behaves differently.  The program execution begins in the ConsoleApplication.Run event and terminates once you exit the Run event (or call Quit).  So basically, everything happens right inside of Run.  If you would like your application to behave in a more GUI-like way (where it continues to run until the user interacts with it somehow), then you can still do that by placing a While loop in your Run event.  For an example of how this works, please see the Event Driven Console.rb project template.
  17.  
  18. * What are the new classes that I can use for console applications?
  19.  
  20.     There are three new classes, five new global methods, one new precompiler directive and one changed global method that pertain to the console application project type.
  21.  
  22. New Class: ConsoleApplication
  23.  
  24. This class has one event, which is the main entry point for the application.
  25.     Run( args() as String ) as Integer
  26.  
  27. 'args' is an array of command line parameters that get passed in to the application.  The first of the parameters will always be the application itself.  The return value for the event will be passed along to the operating system as the return value for your entire application.
  28.  
  29. This class also has one method on it.  It is used for making event-driven console applications.
  30.     DoEvents()
  31.  
  32. This does the same thing as Application.DoEvents, which is, yield time back to REALbasic so we can fire events, etc.
  33.  
  34. New Class: StandardInputStream
  35.  
  36. This class has two methods on it for dealing with input
  37.     Read( count as Integer ) as String
  38.     ReadLine() as String
  39.  
  40. Both Read and ReadLine will block until there is sufficient input to satisfy them.  For Read, this means that your application's execution will halt until there are 'count' bytes available.  It will then return those bytes as a string.  For ReadLine, it will block until the user hits the enter key (or return, if you're using a Mac keyboard).  Note that ReadLine will not return the newline character as a part of the string.  Since there is only one StandardInputStream for the system, you do not need to create a StandardInputStream variable to use; you just use stdin.
  41.  
  42. New Class: StandardOutputStream
  43.  
  44. This class has two methods on it for dealing with output
  45.     Write( data as String )
  46.     WriteLine( data as String )
  47.  
  48. If you use WriteLine, a newline character will automatically be appended to the end of 'data'.  If you do not wish to have a newline character, then use the Write method instead.  Since there is only one StandardOutputStream for the system, you do not need to create a StandardOutputStream variable to use; you just use stdout (or stderr for the error stream).
  49.  
  50. New Global Methods:
  51.  
  52. Print( data as String )
  53.     This will print 'data' out to the terminal and append a newline character to the end of it.  It is a shortcut for StandardOutputStream.WriteLine
  54.  
  55. Input() as String
  56.     This will retrieve a line from the terminal.  It is a shortcut for the StandardInputStream.ReadLine.  Note that it will not return the newline character as a part of the string.
  57.  
  58. stdin as StandardInputStream
  59.     Retreives the global handle to the standard input stream (typically the keyboard on the terminal, though it could be something like a file, serial control, socket, etc on some systems).
  60.  
  61. stdout as StandardOutputStream
  62.     Retreives the global handle to the standard output stream (typically the terminal window, tho it could be something else, just like the StandardInputStream).
  63.  
  64. stderr as StandardOutputStream
  65.     Retrieves the global handle to the standard error stream (typically the same as stdout, but it could be something different as well).
  66.  
  67. Changed Global Methods:
  68.  
  69. Quit( [status as Integer = 0] )
  70.     Quit now takes an optional parameter to return a status code.  When you call Quit, it will automatically terminate your application (just like you were in a GUI project), and return the value that is passed in to it.
  71.  
  72. New Precompiler Directive:
  73.  
  74. TargetHasGUI
  75.     You can use this to write more general code in some of your classes.  For example, you can now write a function like this:
  76.  
  77. Sub DisplayError( err as String )
  78.   #if TargetHasGUI
  79.     MsgBox err
  80.   #else
  81.     stderr.WriteLine err
  82.   #endif
  83. End Sub
  84.